package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysUserPost;
import com.microcdyUser.service.SysUserPostService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysUserPost")
@CrossOrigin
public class SysUserPostController {

    @Autowired
    private SysUserPostService sysUserPostService;

    /***
     * SysUserPost分页条件搜索实现
     * @param sysUserPost
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysUserPost sysUserPost, @PathVariable  int page, @PathVariable  int size){
        //调用SysUserPostService实现分页条件查询SysUserPost
        PageInfo<SysUserPost> pageInfo = sysUserPostService.findPage(sysUserPost, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysUserPost分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysUserPostService实现分页查询SysUserPost
        PageInfo<SysUserPost> pageInfo = sysUserPostService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysUserPost
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysUserPost>> findList(@RequestBody(required = false)  SysUserPost sysUserPost){
        //调用SysUserPostService实现条件查询SysUserPost
        List<SysUserPost> list = sysUserPostService.findList(sysUserPost);
        return new Result<List<SysUserPost>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用SysUserPostService实现根据主键删除
        sysUserPostService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysUserPost数据
     * @param sysUserPost
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysUserPost sysUserPost,@PathVariable Long id){
        //设置主键值
        sysUserPost.setUserId(id);
        //调用SysUserPostService实现修改SysUserPost
        sysUserPostService.update(sysUserPost);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysUserPost数据
     * @param sysUserPost
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysUserPost sysUserPost){
        //调用SysUserPostService实现添加SysUserPost
        sysUserPostService.add(sysUserPost);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysUserPost数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysUserPost> findById(@PathVariable Long id){
        //调用SysUserPostService实现根据主键查询SysUserPost
        SysUserPost sysUserPost = sysUserPostService.findById(id);
        return new Result<SysUserPost>(true,StatusCode.OK,"查询成功",sysUserPost);
    }

    /***
     * 查询SysUserPost全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysUserPost>> findAll(){
        //调用SysUserPostService实现查询所有SysUserPost
        List<SysUserPost> list = sysUserPostService.findAll();
        return new Result<List<SysUserPost>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
